package com.example.ordersystem.utils;

import com.example.ordersystem.pojo.Food;

import java.util.ArrayList;

import java.util.List;

/*
 * 这个是对订单菜品进行添加，删除，以及清空
 * 将订单菜品封装到一个 List<Food> 集合中去
 */
public class Order_Food {

    private static List<Food> foodList1 = new ArrayList<>();

    public static void addFood(Food food) {
        Boolean isExist =false;
        List<Food> order_food = Order_Food.getOrder_Food();
        if(order_food!=null){
            for (Food food1 : order_food) {
                if(food.getFoodName().equals(food1.getFoodName())){
                    int i = food1.getNum() + 1;
                    food1.setNum(i);
                    isExist = true;
                }
            }
        }
        if(!isExist){
            food.setNum(1);
            foodList1.add(food);
        }
    }

    public static List<Food> getOrder_Food() {
        return foodList1;
    }


    public static void deleteOrderFood(Food food) {
        for (Food food1 : foodList1) {
            if (food.toString().equals(food1.toString())) {
                foodList1.remove(food1);
                break;
            }
        }
    }
}
